package com.lancer.anglsrv.words;

import java.util.ArrayList;
import java.util.List;
import java.util.Enumeration;
//import java.util.Collection;
//import java.util.Iterator;

import org.htmlparser.Parser;
//import org.htmlparser.util.NodeList;
//import org.htmlparser.Node;
import org.htmlparser.util.ParserException;

//import java.io.File;
import java.io.BufferedInputStream;
import java.io.IOException;

import java.util.zip.*;
import com.lancer.anglsrv.util.*;

public class CommonParser {
	List<String> words = new ArrayList<String>();
	public void parse(String fileName) {
		//Enumeration<ZipEntry> entries;
		ZipFile zipFile;
		//ZipEntry entry;
		try {
		    Parser parser = new Parser();			
			zipFile = new ZipFile(fileName);
			
			for (ZipEntry entry : iterate(zipFile.entries())) {
				if (!entry.isDirectory()) {
					String entryName = entry.getName();
					int posDot = entryName.lastIndexOf(".");
					if (posDot > 0) {
						String ext = entryName.substring(posDot + 1);
						if (ext.toUpperCase().equals("XML")) {
							BufferedInputStream input = new BufferedInputStream(zipFile.getInputStream(entry));
							byte[] buf = new byte[8192];
							StringBuffer html = new StringBuffer();
							while (input.read(buf, 0, 8192 ) != -1) {
								html.append(buf);
							}
							if (buf.length > 0) {
								html.append(buf);
							}
							//NodeList nodes;
						    //Node node;							
					        //parser.setResource("");
					        //nodes = parser.parse(null);							
							System.out.println(entry.getName());
						}
					}
				}
			}
		/*} catch (ParserException pe) {
			pe.printStackTrace();
			return;*/			
		} catch (IOException e) {
			e.printStackTrace();
			return;		
		};
		
	}
	
	public static <T> Iterable<T> iterate(Enumeration<T> enumeration) {
	    return new IterableEnumeration<T>(enumeration);
	}	
}
